package com.shujia.wyh.day05;

/*
        3.密规则如下：每位数字都加上5,然后用和除以10的余数代替该数字，再将第一位和第四位交换，第二位和第三位交换。结果如图所示。
 */

import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        //创建键盘录入对象
        Scanner sc = new Scanner(System.in);

        //java中换行输出为System.out.println
        //不换行输出System.out.print
        System.out.print("请输入一个4位正整数：");
        int number = sc.nextInt();
        if (number >= 1000 & number <= 9999) {
            int geWei = (number % 10 + 5) % 10;
            int shiWei = (number / 10 % 10 + 5) % 10;
            int baiWei = (number / 10 / 10 % 10 + 5) % 10;
            int qianWei = (number / 10 / 10 / 10 % 10 + 5) % 10;

            //定义临时变量做交换
            int temp = 0;
            temp = geWei;
            geWei = qianWei;
            qianWei = temp;

            int temp2 = 0;
            temp2 = shiWei;
            shiWei = baiWei;
            baiWei = temp2;

            int result = qianWei * 1000 + baiWei * 100 + shiWei * 10 + geWei;
            System.out.println("加密后的数字为：" + result);
        } else {
            System.out.println("输入数据有误");
        }


    }
}
